<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/21
 * Time: 19:52
 */

namespace App\Transformers;


use App\Models\Order;
use App\User;
use League\Fractal\TransformerAbstract;

class OrderTransformer extends TransformerAbstract
{

    protected $availableIncludes = ['good','user'];

    public function transform(Order $order){
        return[
            'id'=>$order->id,
            'good_id'=>$order->good_id,
            'goods_name'=>$order->goods_name,
            'goods_number'=>$order->goods_number,
            'price'=>$order->price,
            'order_type'=>$order->order_type,
            'user_id'=>$order->user_id,
            'username'=>$order->username,
            'order_number'=>$order->order_number,
            'order_payment'=>$order->order_payment,
            'status'=>$order->status,
            'payment_status'=>$order->payment_status,
            'order_ship'=>$order->order_ship,
        ];
    }

    public function includeGood(Order $order){

        return $this->item($order->good,new GoodsinfoTransformer());


    }

    public function includeUser(Order $order){

        return $this->item($order->user,new UsersTransformer(false));
    }
}